package action.entrenador.gesDepDis;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import DBMS.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import clases.AsociarDepDisForm;

/**
 *
 * @author roque
 */
public class AccionAsociar extends Action {
    
    public ActionForward execute(ActionMapping mapping, ActionForm form, 
               HttpServletRequest request, HttpServletResponse response)
               throws Exception {
        AsociarDepDisForm vf = (AsociarDepDisForm) form;
        ActionErrors e = new ActionErrors();
                System.out.println(vf.getDeportista());
        if (vf.getDisciplina().equals("Seleccione Disciplina")){
            request.setAttribute("error",true);
            return mapping.findForward("error");
        }
                
        DataBaseManager dbms = DataBaseManager.getInstance();
        if (dbms.buscarDeportistaCI(vf)) {
            if (dbms.Asociar(vf))
                request.setAttribute("agregado",true);
            else 
                request.setAttribute("ya", true);
            return mapping.findForward("avanzar");
        } else {
            request.setAttribute("errorUsuario",true);
            return mapping.findForward("error");
        }
    }
    
}
